package refactortips.editors.codeSmells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;
import refactortips.editors.CommandMouseAdapter;

import org.eclipse.wb.swt.ResourceManager;

public class FeatureEnvyEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public FeatureEnvyEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmCodeSmell = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmCodeSmell);
		frmCodeSmell.setText("Feature Envy");
		frmCodeSmell.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmCodeSmell.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Link linkRenameMethod1 = new Link(composite_3, SWT.NONE);
		linkRenameMethod1.setBounds(517, 325, 115, 21);
		linkRenameMethod1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkRenameMethod1.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.renameMethodCommand"));
		formToolkit.adapt(linkRenameMethod1, true, true);
		linkRenameMethod1.setText("<a>Rename Method</a>");
		
		Link linkMoveMethod1 = new Link(composite_3, 0);
		linkMoveMethod1.setText("<a>Move Method</a>");
		linkMoveMethod1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkMoveMethod1.setBounds(552, 282, 104, 21);
		formToolkit.adapt(linkMoveMethod1, true, true);
		
		Link linkMoveMethod2 = new Link(composite_3, 0);
		linkMoveMethod2.setText("<a>Move Method</a>");
		linkMoveMethod2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkMoveMethod2.setBounds(407, 347, 104, 21);
		formToolkit.adapt(linkMoveMethod2, true, true);
		
		Link linkExtractMethod2 = new Link(composite_3, 0);
		linkExtractMethod2.setText("<a>Extract Method</a>");
		linkExtractMethod2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod2.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		linkExtractMethod2.setBounds(53, 492, 104, 21);
		formToolkit.adapt(linkExtractMethod2, true, true);
		
		Link linkDivergentChange = new Link(composite_3, 0);
		linkDivergentChange.setText("<a>Divergent Change</a>");
		linkDivergentChange.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkDivergentChange.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.divergentChangeCommand"));
		linkDivergentChange.setBounds(128, 586, 125, 21);
		formToolkit.adapt(linkDivergentChange, true, true);
		
		Link linkStrategy = new Link(composite_3, 0);
		linkStrategy.setText("<a>Strategy</a>");
		linkStrategy.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkStrategy.setBounds(714, 544, 58, 21);
		formToolkit.adapt(linkStrategy, true, true);
		
		Link linkVisitor = new Link(composite_3, 0);
		linkVisitor.setText("<a>Visitor</a>");
		linkVisitor.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkVisitor.setBounds(31, 565, 45, 21);
		formToolkit.adapt(linkVisitor, true, true);
		
		Link linkStrategy2 = new Link(composite_3, 0);
		linkStrategy2.setText("<a>Strategy</a>");
		linkStrategy2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkStrategy2.setBounds(31, 650, 58, 21);
		formToolkit.adapt(linkStrategy2, true, true);
		
		Link linkVisitor2 = new Link(composite_3, 0);
		linkVisitor2.setText("<a>Visitor</a>");
		linkVisitor2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkVisitor2.setBounds(137, 650, 45, 21);
		formToolkit.adapt(linkVisitor2, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tO sentido da exist\u00EAncia de objetos \u00E9 que eles s\u00E3o uma t\u00E9cnica para empacotar dados com os processos usados naqueles dados. Um mau cheiro cl\u00E1ssico \u00E9 um m\u00E9todo que parece estar mais interessado em uma classe do que naquela a qual ela se encontra. O foco mais comum da \u201Cinveja\u201D \u00E9 o dado. N\u00F3s perdemos a conta das vezes que vimos um m\u00E9todo chamando meia-d\u00FAzia de m\u00E9todos \u201Cget\u201D em outro objeto para calcular algum valor. Felizmente a cura \u00E9 \u00F3bvia, o m\u00E9todo claramente quer estar em outro lugar, ent\u00E3o voc\u00EA usa\t\t\t\t\t\t\tpara leva-lo at\u00E9 l\u00E1. Algumas vezes apenas parte do m\u00E9todo sofre de \u201Cinveja\u201D; nesse caso use\t\t\t\t\t\t      na \u201Cparte invejosa\u201D e\t\t\t\t\t\t\t\tpara dar-lhe uma casa dos sonhos.\r\n");
		styledText.setBounds(389, 94, 412, 308);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tClaro que nem todos os casos s\u00E3o diretos. Frequentemente um m\u00E9todo usa funcionalidades de v\u00E1rias classes, ent\u00E3o em qual delas este deve conviver? A heur\u00EDstica que usamos \u00E9 determinar qual classe possui a maior parte dos dados e colocar o m\u00E9todo com esses dados. Esse passo \u00E9 frequentemente facilitado se\t\t\t\t\t\t\t\tfor usado para quebrar o m\u00E9todo em parte que se encaixam em diferentes partes.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(31, 429, 770, 109);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tClaro que existem v\u00E1rios padr\u00F5es sofisticados que quebram essa regra. Dos Ganf of Four \t\t\t\t\te \t\t\t\timediatamente v\u00EAm \u00E0 mente. Kent Beck\u2019s Self Delegation [Beck] \u00E9 outro. Voc\u00EA usa estes para combater o mal cheiro \t\t\t\t\t\t\t\t\t  . A regra de ouro fundamental \u00E9 colocar as coisas juntas que mudam juntas. Os dados e o comportamento que referencia estes dados normalmente mudam juntos, mas h\u00E1 exce\u00E7\u00F5es. Quando as exce\u00E7\u00F5es ocorrem, n\u00F3s movemos o comportamento para manter as mudan\u00E7as em um lugar. \t\t\t\t\te \t\t\t\t\tpermite que voc\u00EA altere o comportamento facilmente porque eles isolam a pequena quantidade de comportamento que precisam ser sobescritos, ao custo de ainda mais indire\u00E7\u00E3o.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(31, 544, 770, 212);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		Label label = new Label(composite_3, SWT.NONE);
		label.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/featureEnvy.jpg"));
		label.setBounds(41, 62, 325, 352);
		formToolkit.adapt(label, true, true);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
